import 'package:bxultimate/app/theme/app_theme.dart';
import 'package:bxultimate/app/theme/gaps.dart';
import 'package:bxultimate/widgets/app/app_title.dart';
import 'package:bxultimate/widgets/mk_page.dart';
import 'package:flutter/material.dart';
import 'package:flutter_widget_from_html/flutter_widget_from_html.dart';
import 'package:get/get.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';

import 'controller.dart';

class OrganizationAnnouncementDetailPage extends StatefulWidget {
  const OrganizationAnnouncementDetailPage({Key? key}) : super(key: key);

  @override
  State<OrganizationAnnouncementDetailPage> createState() =>
      _OrganizationAnnouncementDetailPageState();
}

class _OrganizationAnnouncementDetailPageState
    extends State<OrganizationAnnouncementDetailPage> {
  final controller = Get.find<OrganizationAnnouncementDetailController>();
  final state = Get.find<OrganizationAnnouncementDetailController>().state;

  @override
  Widget build(BuildContext context) {
    return MkPage(
        child: Obx(()=>Scaffold(
          backgroundColor: Colors.transparent,
          appBar: TDNavBar(
            backgroundColor: Colors.transparent,
            title: '${state.info.noticeName}',
          ),
          body: SingleChildScrollView(
            child: _buildBody(),
          ),
        )));
  }

  _buildBody() {
    return Padding(
        padding: EdgeInsets.only(
            left: AppTheme.iDefaultPadding, right: AppTheme.iDefaultPadding),
        child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
          AppTitle(title: '${state.info.noticeName}'),
          Gaps.vGap8,
          Text('${state.info.noticeDescription}'),
          Gaps.vGap8,
          _buildHtml()
        ]));
  }

  _buildHtml() {
    if(state.info.content == null){
      return SizedBox();
    }
    return Column(
      children: [
        ...state.info.content!.map((e) =>  HtmlWidget('${e}'))
      ],
    );
  }

  @override
  void dispose() {
    Get.delete<OrganizationAnnouncementDetailController>();
    super.dispose();
  }
}
